<template>
  <div class="addSupplier">
    <el-dialog
      title="新增供应商"
      :center="true"
      :visible.sync="addDialogVisible"
      width="40%"
      :before-close="SupplierCancel"
    >
      <el-form
        label-width="100px"
        :model="supplierList"
        :rules="rules"
        ref="supplierList"
      >
        <el-form-item label="供应商名称" prop="providerName">
          <el-input
            placeholder="供应商名称"
            v-model="supplierList.providerName"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="SupplierCancel">取 消</el-button>
        <el-button type="primary" @click="addSupplier">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "AddSupplier",
  props: ["addDialogVisible"],
  data() {
    return {
      supplierList: { providerName: "", id: "" },
      rules: {
        providerName: [
          { required: true, message: "请输入供应商名称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    // 取消新增供应商
    SupplierCancel() {
      this.$emit("SupplierCancel", false);
      this.supplierList = { providerName: "", id: "" };
      this.$message("已取消添加");
    },
    // 确认新增供应商
    addSupplier() {
      if (this.supplierList.providerName == "") {
        this.$message({
          message: "请填写供应商名称",
          type: "warning",
        });
      } else {
        this.$emit("addSupplier", this.supplierList, false);
        this.supplierList = { providerName: "", id: "" };
      }
    },
  },
};
</script>
<style lang="scss" scoped></style>
